import requests


def create_url(start_page, end_page):
    base_url = "https://bbs.itheima.com/forum-425-"
    for i in range(start_page, end_page + 1):
        # 构造url
        url = base_url + str(i) + ".html"
        html = do_request(url)
        # 保存成文件
        save_file("网页/" + str(i) + ".html", html)


def save_file(filename, html):
    with open(filename, "w+", encoding="utf-8") as f:
        f.write(html)


def do_request(url):
    # 请求
    response = requests.get(url)
    # 设置编码格式
    response.encoding = "utf-8"
    return response.text


if __name__ == '__main__':
    create_url(1, 5)
